const Router = require('koa-router')

module.exports = app => {
    const router = new Router()

    router.get('/', async (ctx, next) => {
        ctx.type = 'text/html'
        ctx.body = `<h2>Hello Koa!</h2>`
    })

    router.get('/tree', async (ctx) => {
        ctx.body = "tree json数据"
    })

    //如果匹配不到路由则返回404
    router.all('/login', async (ctx) => {    
        ctx.status = 404
        ctx.body = '<h1>~~oops page not found!</h1>'
    })

    app.use(router.routes()).use(router.allowedMethods())
}
